package chapter1_5_sleep;

/**
 *
 * 测试interrupt是否能够打断正在sleep的线程
 * @author huayuhao
 * @date 2020/12/15 16:40
 */
public class SleepInterrupt {

    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(()->{
            try {
                System.out.println("开始睡");
                Thread.sleep(10* 1000);
                System.out.println("睡醒了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        // 启动线程,理论上会睡5s
        thread.start();

        // 将会抛出IllegalArgumentException: timeout value is negative
        //Thread.sleep(-1);

        // 主线程打断正在睡眠的thread线程 将会抛出异常 sleep interrupted
        thread.interrupt();


    }
}
